import React from 'react';
export default class App extends React.Component {
  state = {
    count: 0,
  };

  // 1. 定义事件

  handleClick(num) {
    // 快捷键：cs， 解构state
    const { count } = this.state;
    // 2. setState改变count的值

    // 快捷键：sst， 生成this.setState
    this.setState({
      count: count + num,
    });
  }

  render() {
    // 👍  推荐解构state
    const { count } = this.state;

    return (
      <div>
        <p>当前数值为：{count}</p>
        <hr />
        <button onClick={() => this.handleClick(1)}>+1</button>
        <span>{count}</span>
        <button onClick={() => this.handleClick(-1)}>-1</button>
      </div>
    );
  }
}
